package 多线程.Semaphore信号量;

import java.util.concurrent.Semaphore;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore = new Semaphore(4);
        semaphore.acquire();//抛出Interrupted
        System.out.println("P操作");
        System.out.println("P操作");
        System.out.println();
        semaphore.acquire();//抛出Interrupted
        System.out.println("P操作");
        System.out.println();
        semaphore.acquire();//抛出Interrupted
        System.out.println("P操作");
        System.out.println("P操作");
        System.out.println("P操作");
        System.out.println();
        semaphore.acquire(2);//抛出Interrupted
        System.out.println("P操作");

        System.out.println();
        semaphore.release(4);
    }
}
